package cloneExample;

/**
 * 深度克隆实现方式二： 利用构造方法实现
 */
public class CloneExample2 {
	public static void main(String[] args) {
		Address address = new Address(110, "beijing");
		People p1 = new People(1, "Java", address);
		// 利用构造方法，重新创造出来一个People对象
		People p2 = new People(p1.getId(), p1.getName(), new Address(address.getId(), address.getCity()));

		p1.getAddress().setCity("guangzhou");

		System.out.println("p1:" + p1.getAddress().getCity()); // guangzhou
		System.out.println("p2:" + p2.getAddress().getCity()); // beijing
	}
}
